package com.gitee.sop.sopauth.controller;

import com.gitee.sop.servercommon.annotation.Open;
import com.gitee.sop.servercommon.bean.OpenContext;
import com.gitee.sop.servercommon.bean.ServiceContext;
import com.gitee.sop.sopauth.controller.param.CodeParam;
import com.gitee.sop.sopauth.service.SendCodeHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 验证码
 *
 * @author admin
 */
@Api(tags = "验证码信息")
@RestController
@RequestMapping("code")
public class CodeController {

    @Autowired
    private SendCodeHandler sendCodeHandler;

    @ApiOperation(value = "获取验证码", notes = "获取验证码")
    @Open(value = "open.auth.code.send")
    @PostMapping("/send")
    public Object send(@RequestBody CodeParam codeParam) {
        OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
        codeParam.setAppId(openContext.getAppId());
        return sendCodeHandler.handleCode(codeParam);
    }
}
